package tp.badugi.server;

public enum Card {
	ACE_SPADES("A", "S"), ACE_DIAMONDS("A", "D"), ACE_HEARTS("A", "H"), ACE_CLUBS("A", "C"),
	TWO_SPADES("2", "S"), TWO_DIAMONDS("2", "D"), TWO_HEARTS("2", "H"), TWO_CLUBS("2", "C"),
	THREE_SPADES("3", "S"), THREE_DIAMONDS("3", "D"), THREE_HEARTS("3", "H"), THREE_CLUBS("3", "C"),
	FOUR_SPADES("4", "S"), FOUR_DIAMONDS("4", "D"), FOUR_HEARTS("4", "H"), FOUR_CLUBS("4", "C"),
	FIVE_SPADES("5", "S"), FIVE_DIAMONDS("5", "D"), FIVE_HEARTS("5", "H"), FIVE_CLUBS("5", "C"),
	SIX_SPADES("6", "S"), SIX_DIAMONDS("6", "D"), SIX_HEARTS("6", "H"), SIX_CLUBS("6", "C"),
	SEVEN_SPADES("7", "S"), SEVEN_DIAMONDS("7", "D"), SEVEN_HEARTS("7", "H"), SEVEN_CLUBS("7", "C"),
	EIGHT_SPADES("8", "S"), EIGHT_DIAMONDS("8", "D"), EIGHT_HEARTS("8", "H"), EIGHT_CLUBS("8", "C"),
	NINE_SPADES("9", "S"), NINE_DIAMONDS("9", "D"), NINE_HEARTS("9", "H"), NINE_CLUBS("9", "C"),
	TEN_SPADES("T", "S"), TEN_DIAMONDS("T", "D"), TEN_HEARTS("T", "H"), TEN_CLUBS("T", "C"),
	JACK_SPADES("J", "S"), JACK_DIAMONDS("J", "D"), JACK_HEARTS("J", "H"), JACK_CLUBS("J", "C"),
	QUEEN_SPADES("Q", "S"), QUEEN_DIAMONDS("Q", "D"), QUEEN_HEARTS("Q", "H"), QUEEN_CLUBS("Q", "C"),
	KING_SPADES("K", "S"), KING_DIAMONDS("K", "D"), KING_HEARTS("K", "H"), KING_CLUBS("K", "C");
	
	/**
	 * Get the <code>enum</code> representation of the card.
	 * 
	 * @param twoCharacterCode
	 * @return <code>enum</code> representation or <code>null</code> if doesn't exist.
	 */
	public static Card fromString(String twoCharacterCode) {
		for (Card card : Card.values()) {
			if (twoCharacterCode.compareTo(card.toString()) == 0) {
				return card;
			}
		}
		
		// Otherwise
		return null; 
	}
	// Define suits
	public static final String SPADE = "S";
	public static final String DIAMOND = "D";
	public static final String HEART = "H";
	
	public static final String CLUB = "C";
	// Define ranks
	public static final String ACE = "A";
	public static final String TWO = "2";
	public static final String THREE = "3";
	public static final String FOUR = "4";
	public static final String FIVE = "5";
	public static final String SIX = "6";
	public static final String SEVEN = "7";
	public static final String EIGHT = "8";
	public static final String NINE = "9";
	public static final String TEN = "T";
	public static final String JACK = "J";
	public static final String QUEEN = "Q";
	
	public static final String KING = "K";
	private final String rank;
	
	private final String suit;
	
	Card(String rank, String suit) {
		this.rank = rank;
		this.suit = suit;
	}
	
	public String getRank() {
		return rank;
	}
	
	public String getSuit() {
		return suit;
	}
	
	public boolean sameRank(Card card) {
		return rank.equals(card.getRank()) ? true : false;
	}
	
	public boolean sameSuit(Card card) {
		return suit.equals(card.getSuit()) ? true : false;
	}

	@Override
	public String toString() {
		return rank + suit;
	}
}
